function [ vertSurfArea ] = CompSurfAreaPerVert( vertices, triangles )
%COMPSURFPERVERT Summary of this function goes here
%   Detailed explanation goes here

nbTri=size(triangles,1);
nbV=size(vertices,1);

vertSurfArea=zeros(nbV,1);

surfArea=0;
for i=1:nbTri
    % Compute the surface area of the triangle
    x=[vertices(triangles(i,1),1),vertices(triangles(i,2),1),vertices(triangles(i,3),1)];
    y=[vertices(triangles(i,1),2),vertices(triangles(i,2),2),vertices(triangles(i,3),2)];
    z=[vertices(triangles(i,1),3),vertices(triangles(i,2),3),vertices(triangles(i,3),3)];
    ons = [1 1 1];
    triSurArea = 0.5*sqrt(det([x;y;ons])^2 + det([y;z;ons])^2 + det([z;x;ons])^2);
    surfArea=surfArea+triSurArea;
    
    vertSurfArea(triangles(i,1))=vertSurfArea(triangles(i,1))+triSurArea/3;
    vertSurfArea(triangles(i,2))=vertSurfArea(triangles(i,2))+triSurArea/3;
    vertSurfArea(triangles(i,3))=vertSurfArea(triangles(i,3))+triSurArea/3;
end

end

